home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / utils / NameUtil.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  2.0 KB  |  78 lines

  1. package mx.utils
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.utils.getQualifiedClassName;
  5.    import mx.core.IRepeaterClient;
  6.    import mx.core.mx_internal;
  7.    
  8.    use namespace mx_internal;
  9.    
  10.    public class NameUtil
  11.    {
  12.       mx_internal static const VERSION:String = "3.2.0.3958";
  13.       
  14.       private static var counter:int = 0;
  15.       
  16.       public function NameUtil()
  17.       {
  18.          super();
  19.       }
  20.       
  21.       public static function displayObjectToString(param1:DisplayObject) : String
  22.       {
  23.          var result:String = null;
  24.          var o:DisplayObject = null;
  25.          var s:String = null;
  26.          var indices:Array = null;
  27.          var displayObject:DisplayObject = param1;
  28.          try
  29.          {
  30.             o = displayObject;
  31.             while(o != null)
  32.             {
  33.                if(o.parent && o.stage && o.parent == o.stage)
  34.                {
  35.                   break;
  36.                }
  37.                s = o.name;
  38.                if(o is IRepeaterClient)
  39.                {
  40.                   indices = IRepeaterClient(o).instanceIndices;
  41.                   if(indices)
  42.                   {
  43.                      s += "[" + indices.join("][") + "]";
  44.                   }
  45.                }
  46.                result = result == null ? s : s + "." + result;
  47.                o = o.parent;
  48.             }
  49.          }
  50.          catch(e:SecurityError)
  51.          {
  52.          }
  53.          return result;
  54.       }
  55.       
  56.       public static function createUniqueName(param1:Object) : String
  57.       {
  58.          if(!param1)
  59.          {
  60.             return null;
  61.          }
  62.          var _loc2_:* = getQualifiedClassName(param1);
  63.          var _loc3_:int = int(_loc2_.indexOf("::"));
  64.          if(_loc3_ != -1)
  65.          {
  66.             _loc2_ = _loc2_.substr(_loc3_ + 2);
  67.          }
  68.          var _loc4_:int = int(_loc2_.charCodeAt(_loc2_.length - 1));
  69.          if(_loc4_ >= 48 && _loc4_ <= 57)
  70.          {
  71.             _loc2_ += "_";
  72.          }
  73.          return _loc2_ + counter++;
  74.       }
  75.    }
  76. }
  77.  
  78.